

//-------Aliases-------//
private alias object.value0 : object.red
private alias object.value1 : object.blu
private alias object.value2 : object.grn

private alias object.value10 : object.store
private alias object.value20 : object.process

public alias saveRAM[294] : saved.graphics

// Static Values

// Tables

reserve function processColor
reserve function actualColor

event ObjectMain
	temp0 = 0
	while temp0 < 8
		temp1 = 0
		while temp1 < 256
			GetPaletteEntry(temp0, temp1, object.store)			
			CallFunction(processColor)			
			SetPaletteEntry(temp0, temp1, object.store)
			temp1++
		loop
	temp0++
	loop	
	
	switch object.propertyValue
		case 0
			color1 = 32
			color2 = 64
			color3 = 96
			color4 = 128
			color5 = 160
			color6 = 192
			color7 = 224
			break
		case 1
			color1 = 36
			color2 = 72
			color3 = 108
			color4 = 144
			color5 = 180
			color6 = 216
			color7 = 252
			break
		case 2
			color1 = 52
			color2 = 87
			color3 = 116
			color4 = 144
			color5 = 172
			color6 = 206
			color7 = 255
			break			
	end switch
	
	temp0 = 0
	while temp0 < 64
		GetTableValue(object.store, temp0, PlayerObject_SonicSuperPal)
		CallFunction(processColor)
		SetTableValue(object.store, temp0, PlayerObject_SonicSuperPal)
				
		GetTableValue(object.store, temp0, PlayerObject_SonicSuperAltPal)
		CallFunction(processColor)
		SetTableValue(object.store, temp0, PlayerObject_SonicSuperAltPal)
		temp0++
	loop
	
	temp0 = 0
	while temp0 < 24
		GetTableValue(object.store, temp0, PlayerObject_TailsSuperPal)
		CallFunction(processColor)
		SetTableValue(object.store, temp0, PlayerObject_TailsSuperPal)
				
		GetTableValue(object.store, temp0, PlayerObject_TailsSuperAltPal)
		CallFunction(processColor)
		SetTableValue(object.store, temp0, PlayerObject_TailsSuperAltPal)
		temp0++
	loop
	
	temp0 = 0
	while temp0 < 30
		GetTableValue(object.store, temp0, PlayerObject_KnuxSuperPal)
		CallFunction(processColor)
		SetTableValue(object.store, temp0, PlayerObject_KnuxSuperPal)
				
		GetTableValue(object.store, temp0, PlayerObject_KnuxSuperAltPal)
		CallFunction(processColor)
		SetTableValue(object.store, temp0, PlayerObject_KnuxSuperAltPal)
		temp0++
	loop	
	
	temp0 = 0
	while temp0 < 32
		GetTableValue(object.store, temp0, PlayerObject_AmySuperPal)
		CallFunction(processColor)
		SetTableValue(object.store, temp0, PlayerObject_AmySuperPal)
				
		GetTableValue(object.store, temp0, PlayerObject_AmySuperAltPal)
		CallFunction(processColor)
		SetTableValue(object.store, temp0, PlayerObject_AmySuperAltPal)
		temp0++
	loop	

	temp0 = 0
	while temp0 < 44
		GetTableValue(object.store, temp0, PlayerObject_NatsukiSuperPal)
		CallFunction(processColor)
		SetTableValue(object.store, temp0, PlayerObject_NatsukiSuperPal)
				
		GetTableValue(object.store, temp0, PlayerObject_NatsukiSuperAltPal)
		CallFunction(processColor)
		SetTableValue(object.store, temp0, PlayerObject_NatsukiSuperAltPal)
		temp0++
	loop	

	temp0 = 0
	while temp0 < 40
		GetTableValue(object.store, temp0, PlayerObject_YuriSuperPal)
		CallFunction(processColor)
		SetTableValue(object.store, temp0, PlayerObject_YuriSuperPal)
				
		GetTableValue(object.store, temp0, PlayerObject_YuriSuperAltPal)
		CallFunction(processColor)
		SetTableValue(object.store, temp0, PlayerObject_YuriSuperAltPal)
		temp0++
	loop	

	temp0 = 0
	while temp0 < 55
		GetTableValue(object.store, temp0, PlayerObject_SayoriSuperPal)
		CallFunction(processColor)
		SetTableValue(object.store, temp0, PlayerObject_SayoriSuperPal)
				
		GetTableValue(object.store, temp0, PlayerObject_SayoriSuperAltPal)
		CallFunction(processColor)
		SetTableValue(object.store, temp0, PlayerObject_SayoriSuperAltPal)
		temp0++
	loop	

	temp0 = 0
	while temp0 < 55
		GetTableValue(object.store, temp0, PlayerObject_MonikaSuperPal)
		CallFunction(processColor)
		SetTableValue(object.store, temp0, PlayerObject_MonikaSuperPal)
				
		GetTableValue(object.store, temp0, PlayerObject_MonikaSuperAltPal)
		CallFunction(processColor)
		SetTableValue(object.store, temp0, PlayerObject_MonikaSuperAltPal)
		temp0++
	loop	

	object.type = TypeName[Blank Object]
end event

function processColor
	switch object.propertyValue
		case 0 //emulated
			//object.store &= 0xE0E0E0
			break
		case 1 //measured
			object.red = object.store
			object.red &= 0xE00000
			object.red >>= 3
			object.red *= 9
			
			object.blu = object.store
			object.blu &= 0x00E000
			object.blu >>= 3
			object.blu *= 9
			
			object.grn = object.store
			object.grn &= 0x0000E0
			object.grn >>= 3
			object.grn *= 9
			
			object.store = object.red
			object.store += object.blu
			object.store += object.grn
			break
		case 2 //actual			
			object.process = object.store
			object.process &= 0xE00000
			object.process >>= 21
			CallFunction(actualColor)
			object.red = object.process
			object.red <<= 16				
			
			object.process = object.store
			object.process &= 0x00E000
			object.process >>= 13
			CallFunction(actualColor)
			object.blu = object.process
			object.blu <<= 8
			
			object.process = object.store
			object.process &= 0xE0
			object.process >>= 5
			CallFunction(actualColor)
			object.grn = object.process				
			
			object.store = object.red
			object.store += object.blu
			object.store += object.grn
			break
	end switch
end function

function actualColor
	switch object.process
		case 0
			object.process = 0
			break
		case 1
			object.process = 52
			break
		case 2
			object.process = 87
			break
		case 3
			object.process = 116
			break
		case 4
			object.process = 144
			break
		case 5
			object.process = 172
			break
		case 6
			object.process = 206
			break
		case 7
			object.process = 255
			break
	end switch
end function


event ObjectDraw
end event


event ObjectStartup
	CreateTempObject(TypeName[Palette Police], saved.graphics, 0, 0)
	object[tempObjectPos].priority = PRIORITY_ACTIVE_PAUSED
end event

event RSDKDraw
	DrawSprite(0)
end event

event RSDKLoad
	LoadSpriteSheet("Global/Display.gif")
	SpriteFrame(-16, -16, 32, 32, 1, 143)
end event
